//
//  CollectionViewController.m
//  Leisure
//
//  Created by 大展 on 16/7/5.
//  Copyright © 2016年 大展. All rights reserved.
//

#import "CollectionViewController.h"

@interface CollectionViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation CollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    [self.tableView registerNib:[UINib nibWithNibName:@"ReadListCell" bundle:nil] forCellReuseIdentifier:@"ReadListModel_cell"];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [[CoreDataManager defaultManager] selectAllCollectionModel].count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    ReadListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReadListModel_cell" forIndexPath:indexPath];

    [cell setCellWithCollectionModel:[[CoreDataManager defaultManager] selectAllCollectionModel][indexPath.row]];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return 200;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    CollectionDetailViewController *VC = [[CollectionDetailViewController alloc]initWithNibName:@"CollectionDetailViewController" bundle:nil];

    VC.html = [[[CoreDataManager defaultManager] selectAllCollectionModel][indexPath.row] html];
    [self.navigationController pushViewController:VC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
